// 预设菜品数据库
const recipes = {
  "番茄炒蛋": [
    { name: "鸡蛋", quantity: "3个" },
    { name: "番茄", quantity: "2个" },
    { name: "食用油", quantity: "适量" },
    { name: "盐", quantity: "适量" },
    { name: "糖", quantity: "少许" }
  ],
  "宫保鸡丁": [
    { name: "鸡胸肉", quantity: "200g" },
    { name: "花生米", quantity: "50g" },
    { name: "干辣椒", quantity: "3-5个" },
    { name: "花椒", quantity: "适量" },
    { name: "葱", quantity: "1根" },
    { name: "姜", quantity: "适量" },
    { name: "蒜", quantity: "2瓣" },
    { name: "生抽", quantity: "1勺" },
    { name: "老抽", quantity: "半勺" },
    { name: "醋", quantity: "1勺" },
    { name: "糖", quantity: "1勺" },
    { name: "盐", quantity: "适量" },
    { name: "食用油", quantity: "适量" }
  ],
  "青椒肉丝": [
    { name: "猪里脊肉", quantity: "150g" },
    { name: "青椒", quantity: "2个" },
    { name: "姜", quantity: "适量" },
    { name: "蒜", quantity: "2瓣" },
    { name: "生抽", quantity: "1勺" },
    { name: "老抽", quantity: "半勺" },
    { name: "料酒", quantity: "1勺" },
    { name: "盐", quantity: "适量" },
    { name: "食用油", quantity: "适量" }
  ],
  "麻婆豆腐": [
    { name: "嫩豆腐", quantity: "300g" },
    { name: "牛肉末", quantity: "100g" },
    { name: "郫县豆瓣酱", quantity: "2勺" },
    { name: "花椒粉", quantity: "适量" },
    { name: "葱", quantity: "1根" },
    { name: "姜", quantity: "适量" },
    { name: "蒜", quantity: "2瓣" },
    { name: "生抽", quantity: "1勺" },
    { name: "老抽", quantity: "半勺" },
    { name: "糖", quantity: "半勺" },
    { name: "盐", quantity: "适量" },
    { name: "食用油", quantity: "适量" }
  ],
  "红烧肉": [
    { name: "五花肉", quantity: "500g" },
    { name: "冰糖", quantity: "30g" },
    { name: "生抽", quantity: "3勺" },
    { name: "老抽", quantity: "1勺" },
    { name: "料酒", quantity: "2勺" },
    { name: "葱", quantity: "2根" },
    { name: "姜", quantity: "适量" },
    { name: "八角", quantity: "2个" },
    { name: "桂皮", quantity: "1小段" },
    { name: "盐", quantity: "适量" },
    { name: "食用油", quantity: "适量" }
  ]
};

/**
 * 根据菜品名称获取食材清单
 * @param {string} dishName - 菜品名称
 * @returns {Array|null} 食材清单数组，如果找不到返回null
 */
function getIngredientsByDishName(dishName) {
  return recipes[dishName] || null;
}

/**
 * 获取所有菜品名称
 * @returns {Array} 所有菜品名称的数组
 */
function getAllDishNames() {
  return Object.keys(recipes);
}

/**
 * 模糊匹配菜品名称
 * @param {string} input - 用户输入
 * @returns {string|null} 匹配到的菜品名称，如果没有匹配到返回null
 */
function fuzzyMatchDishName(input) {
  const dishNames = getAllDishNames();
  
  // 精确匹配
  if (dishNames.includes(input)) {
    return input;
  }
  
  // 简单的模糊匹配（检查是否包含）
  for (const dishName of dishNames) {
    if (dishName.includes(input) || input.includes(dishName)) {
      return dishName;
    }
  }
  
  return null;
}

export { recipes, getIngredientsByDishName, getAllDishNames, fuzzyMatchDishName };
